<?php include('../../variables/variables.php'); ?>

<?php

if(!session_id()) session_start(); 
$con = mysql_connect($dbserver, $dbuser, $dbpass);
if ($con)
{
	mysql_select_db($db, $con);
	
	if ( $_POST['media_id'] && isset($_POST['cost']) && $_POST['media_type_id'])
	{
		
		$q = fquery($add_inventory, array($_POST['cost']*100, $_POST['media_id'], $_POST['media_type_id']));
		$result = mysql_query($q);
		mysql_close($con);
		if ($result)
		{
			header("location: /manage_inventory.php?action=display&id=". $_POST['media_id']. "&msg=New book added successfully!");
		}
		else
		{
			header("location: /manage_inventory.php?action=display&id=". $_POST['media_id']. "&msg=Failed to add the new book to the system.");
		}
	}
	else
	{
		mysql_close($con);
		header("location: /manage_inventory.php?action=display&id=". $_POST['media_id']. "&err=Please fill in all fields.");
	}
}

?>
